using System;
using System.IO;

namespace SAP.BusinessOne.Web.Proxy
{
    static class WebExtension
    {
        public static byte[] ToBinary(this Stream source)
        {
            byte[] buffer = new byte[16 * 1024];
            using (var ms = new MemoryStream())
            {
                int read;
                while ((read = source.Read(buffer, 0, buffer.Length)) > 0)
                {
                    ms.Write(buffer, 0, read);
                }
                return ms.ToArray();
            }
        }

        public static string GetHost(this Uri source)
        {
            return string.Format("{0}://{1}", source.Scheme, source.Authority);
        }
    }
}